package com.example.springbootdemo.controller;

import com.example.springbootdemo.service.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@RestController
@RequestMapping("/qiniu")
public class FileUploadController {
    @Resource
    private FileService fileService;
    @PostMapping("/upload")
    public String upLoadImage(@RequestParam("file") MultipartFile file){
        System.out.println("进入方法");
        if(!file.isEmpty()){
            String path = fileService.uploadQNImg(file);
            if(path.equals("失败")){
                return "上传失败！";
            }else{
                return "图片链接："+path;
            }
        }
        return "上传失败：空文件";
    }
    @DeleteMapping("/delete")
    public Integer deleteImage(@RequestParam("imgUrl") String imgUrl){
        int res = fileService.deleteImg(imgUrl);
        return res == 1 ? res : 0;
    }

}